package com.ruoyi.web.controller.system;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.YonbipTokenUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/cq/dept")
public class CqDeptController  extends BaseController
{

    public void ApiQueryDept(){
        YonbipTokenUtil yonbipTokenUtil= new YonbipTokenUtil();
        // 获取token

        // System.out.println(token);
        // 请求的OpenAPI接口地址，注意nccloud前面没有"/"
        String apiuri = "nccloud/api/riaorg/org/dept/queryDeptByEnableState";
        JSONObject jsonObject=new JSONObject();
        List<String>  list=new ArrayList<>();
        list.add("2");
        jsonObject.set("enablestate",list.toString());
        jsonObject.set("version","1");
        String requestParam =jsonObject.toString();
        // 携带token访问接口，获取结果
        String result = null;
        List<String> lines=new ArrayList<>();
        try
        {
            result = yonbipTokenUtil.callAPI(apiuri, requestParam);
          JSONArray jsonArray=new JSONArray();
            jsonArray=JSONUtil.parseArray(result);
            if(jsonArray.size()>0){
                for(int a=0;a<jsonArray.size();a++){
                    JSONObject jsonObject1= (JSONObject) jsonArray.get(0);
                    lines.add(jsonObject1.getStr("")+"|"+jsonObject1.getStr("")+"|"+jsonObject1.getStr("")+"|"+jsonObject1.getStr("")+"|"+jsonObject1.getStr("")+"|"+jsonObject1.getStr("enablestate"));
                }
            }
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        System.out.println(result);
    }
}
